<template>
    <div>
        <div class="wxUserListItem" 
            v-for="(item,index) in friendChatList" 
            :key="index" 
            @click="selectedFriendChatFun(item)"
            :class="selectedFriendChat.uniqueId === item.uniqueId ? 'selectedFriendChat' : ''">
            <div class="wxUserListItemImg">
                <img :src="item.avatar" alt="">
            </div>
            <div class="wxUserListItemNameLastMsg">
                <div class="wxUserListItemTitleTip">
                    <div class="wxUserListItemTitle">{{ item.name }}</div>
                    <div class="wxUserListItemTip">{{ item.dateTime }}</div>
                </div>
                <div class="wxUserListItemTitleTip">
                    <div class="wxUserListItemTitleSimple">{{ item.lastMsg }}</div>
                    <div class="wxUserListItemTip">{{ item.state }}</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>    
export default {
    name: 'FriendList',
    props:{
        friendChatList: {
            type: Array,
            default: () => []
        },
    },
    data() {
        return {
            // 选中的聊天用户
            selectedFriendChat: {},
        };
    },
    methods:{
        selectedFriendChatFun(item){
            this.$emit('selectedFriendChatEmit', item);
            this.selectedFriendChat = item;
        }
    },
}
</script>
<style scoped>
.wxUserListItem{
    height: 60px;
    background: var(--wxUserListItemColorBackground);
    color: var(--wxUserListItemColor);
    text-align: center;
    margin-bottom: 1px;
    display: flex;
    align-items: center;
}
.wxUserListItem:hover {
    background: var(--wxUserListItemHoverBackground);
    cursor: pointer;
}
.wxUserListItem:active {
    background: var(--wxUserListItemActiveBackground);
}
.wxUserListItemImg{
    width: 40px;
    height: 40px;
    min-width: 40px;
    max-width: 40px;
    border-radius: 5px;
    overflow: hidden;
    margin-left: 10px;
    margin-right: 10px;
}
.wxUserListItemImg img{
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.wxUserListItemNameLastMsg{
    width: calc(100% - 60px);
}
.wxUserListItemTitleTip{
    display: flex;
    justify-content: space-between;
    width: 100%;
}
.wxUserListItemTip{
    width: 60px;
    max-width: 60px;
    min-width: 60px;
    color: var(--wxUserListItemTipColor);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: space-around;
}
.wxUserListItemTitle{
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow-x: hidden;
    max-width: calc(100% - 50px);

    font-weight: bold;
}
.wxUserListItemTitleSimple {
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow-x: hidden;
    max-width: calc(100% - 50px);

    font-size: 14px;
    color: var(--wxUserListItemTitleSimpleColor);
}
.selectedFriendChat{
    background: var(--selectedFriendChatBackground);
}
</style>